import type { SysAuditLog } from '@nbase/db';
import type { IAuditLog, IPaginationResponse } from '@nbase/shared';

/**
 * SysAuditLog -> IAuditLog 映射（对外返回使用）
 */
export function toAuditLog(log: SysAuditLog): IAuditLog {
  return {
    id: log.id,
    userId: log.userId,
    username: log.username,
    module: log.module,
    operationType: log.operationType,
    description: log.description,
    method: log.method,
    path: log.path,
    params: log.params,
    body: log.body,
    statusCode: log.statusCode,
    response: log.response,
    errorMsg: log.errorMsg,
    ip: log.ip,
    userAgent: log.userAgent,
    duration: log.duration,
    createdBy: log.createdBy,
    createdAt: log.createdAt?.toISOString(),
  };
}

/**
 * 分页结果 SysAuditLog -> IAuditLog
 */
export function toAuditLogPage(
  page: IPaginationResponse<SysAuditLog>
): IPaginationResponse<IAuditLog> {
  return {
    ...page,
    items: page.items.map(toAuditLog),
  };
}

